package com.mini.gateway.web.domain;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
 * DataTableResult
 *
 */
public class LayTableResult<T> extends JsonResult {

    private long count;

    public LayTableResult() {
        super();
    }

    public static LayTableResult success() {
        LayTableResult result = new LayTableResult<>();
        result.success = true;
        result.code = ResultConstants.NORMAL_TB.getCode();
        result.msg = ResultConstants.NORMAL.getMsg();
        return result;
    }

    public static <T> LayTableResult success(List<T> data) {
        LayTableResult<T> result = new LayTableResult<>();
        result.success = true;
        result.code = ResultConstants.NORMAL_TB.getCode();
        result.msg = ResultConstants.NORMAL.getMsg();
        result.data = data;
        result.count = data != null ? data.size() : 0;
        return result;
    }

   public static <T> LayTableResult success(IPage page){
        LayTableResult<T> result = new LayTableResult<>();
        result.success = true;
        result.code = ResultConstants.NORMAL_TB.getCode();
        result.msg = ResultConstants.NORMAL.getMsg();
        result.data = page.getRecords();
        result.count = page.getTotal();
        return result;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }
}
